<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>用户注册</title>
		<!-- Bootstrap core CSS -->
		<link th:href="@{/asserts/css/bootstrap.min.css}" href="asserts/css/bootstrap.min.css" rel="stylesheet">
		<!-- Custom styles for this template -->
		<link th:href="@{/asserts/css/signin.css}" href="asserts/css/signin.css" rel="stylesheet">
	</head>

	<body class="text-center">
	<div class="col-lg-3"></div>

	<div class="col-lg-6">
		<div >
			<form class="form-signin" id="registForm">

				<img class="mb-4" src="asserts/img/ysu1.jpg"  width="72" height="72">
				<h1 class="h3 mb-3 font-weight-normal">用户注册</h1>

				<label class="sr-only">学校名称</label>
				<input id="universityName" type="text" class="form-control" name="universityName" placeholder="某某大学" required="" autofocus="">

				<label class="sr-only">学号</label>
				<input id="studentID" type="text" class="form-control" name="StudentID" placeholder="学号" required="" autofocus="">

				<label class="sr-only">姓名</label>
				<input id="name" type="text" class="form-control" name="username" placeholder="姓名" required="" autofocus="">

				<label class="sr-only">密码</label>
				<input id="password1" type="password" class="form-control" name="password" placeholder="密码" required="" >


				<label class="sr-only">确认密码</label>
				<input id="password2" type="password" class="form-control" name="repeatpassword" placeholder="确认密码" required="">

				<a name="messege" th:text="${session.registMessage}" style="color:red"></a>


			</form>
		</div>

		<div >
			<button class="btn btn-lg btn-primary btn-block" type="submit" onclick="toRegist()">注册</button>

			<a href="login">去登录</a>
		</div>
	</div>

	<div class="col-lg-3"></div>

	</body>
	<script type="text/javascript" src="webuploader/examples/image-upload/jquery.js"></script>
	<script>
		function toRegist() {
			var universityName = document.getElementById("universityName").value;
			console.log(universityName);
			var studentID = document.getElementById("studentID").value;
			var name = document.getElementById("name").value;
			var password1 = document.getElementById("password1").value;
			var password2 = document.getElementById("password2").value;
			if(universityName.length==0){
				alert("学校名称不能为空");
			}else if(studentID.length==0){
				alert("学号不能为空");
			}else if(name.length==0){
				alert("姓名不能为空");
			}else if(password1.length<6){
				alert("密码最少6位");
			}else if(password1!=password2){
				alert("两次输入的密码不一致");
			}else{
				var form = new FormData(document.getElementById("registForm"));
				$.ajax({
					url:"studentregister",
					type:"post",
					dataType:"html",
					data:form,
					cache:false,
					processData:false,
					contentType:false,
					success: function (data) {
						if(data=="success"){
							alert("注册成功，前去登录吧！");
							location.href="login";
						}else {
							alert(data);
						}
					},
					error:function (data) {
						console.log("error");
						alert("系统错误");
					}
				})
			}

		}
	</script>
</html>